package org.aplikator.server.descriptor;

import org.aplikator.client.descriptor.CheckBoxDTO;
import org.aplikator.client.descriptor.WidgetDTO;
import org.aplikator.server.Context;

public class CheckBox implements Widget, HasProperty<Boolean> {

    private Property<Boolean> property;

    private boolean labelAbove = true;

    public CheckBox(Property<Boolean> property) {
        this.property = property;
    }

    public Property<Boolean> getProperty() {
        return property;
    }

    public WidgetDTO getWidgetDescriptor(Context ctx) {
        CheckBoxDTO desc = new CheckBoxDTO(property.clientClone(ctx));
        desc.setLabelAbove(labelAbove);
        return desc;
    }

    public void registerProperties(Form form) {
        form.addProperty(property);
    }

    public boolean isLabelAbove() {
        return labelAbove;
    }

    public CheckBox setLabelAbove(boolean labelAbove) {
        this.labelAbove = labelAbove;
        return this;
    }
}
